<meta charset="utf-8">
<meta name="viewport" content="width=device-width">

{{ define "partials/get-title" }}
{{ $separator := .Site.Params.titleSeparator | default "|" }}
{{ $primarySep := $separator }}
{{ $secondarySep := $separator }}
{{ if reflect.IsSlice $separator }}
{{ $primarySep = index $separator 0 }}
{{ $secondarySep = index $separator 1 | default (index $separator 0) }}
{{ end }}
{{ $title := .Site.Title }}
{{/*  Generate prefix  */}}
{{ $prefix := "" }}
{{ if .Params.Title }}
{{ $prefix = .Params.Title }}
{{/*  Deprecation warning(v1.0.0) starts */}}
{{ $layout := partial "utils/hyphenate" (.Layout | default .Type) }}
{{/*  Deprecation warning(v1.0.0) ends */}}
{{ if and (eq .Type "docs") (ne $layout "doc-list") }}
{{ $docTitle := "" }}
{{ $bundles := partial "get-bundles" . }}
{{ range $bundles.Reverse }}
{{ $version := findRE "v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?" (path.Base .Permalink) }}
{{/*  Deprecation warning(v1.0.0) starts */}}
{{ $parentLayout := partial "utils/hyphenate" (.Parent.Layout | default .Parent.Type) }}
{{ $layout := partial "utils/hyphenate" (.Layout | default .Type) }}
{{/*  Deprecation warning(v1.0.0) ends */}}
{{ if and (eq $parentLayout "doc-list") (ne $layout "doc-list") }}
{{ $docTitle = .Title }}
{{ else if $version }}
{{ $docTitle = .Title }}
{{ end }}
{{ end }}
{{/*  Doc title  */}}
{{ $version := findRE "v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?" (path.Base .Permalink) }}
{{/*  Deprecation warning(v1.0.0) starts */}}
{{ $parentLayout := partial "utils/hyphenate" (.Parent.Layout | default .Parent.Type) }}
{{/*  Deprecation warning(v1.0.0) ends */}}
{{ if or (eq $parentLayout "doc-list") $version }}
{{ $prefix = $docTitle }}
{{ else }}
{{ $prefix = print $prefix " " $secondarySep " " $docTitle }}
{{ end }}
{{ end }}
{{ end }}
{{/*  Add prefix  */}}
{{ with $prefix }}
{{ $title = print . " " $primarySep " " $title }}
{{ end }}
{{ return $title }}
{{ end }}
<title>{{ partial "get-title" . }}</title>

{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
<link rel="stylesheet" href="{{ $eurekaCSS.Permalink }}">

{{- $eurekaJS := resources.Get "js/eureka.js" | minify }}
<script defer src="{{ $eurekaJS.Permalink }}"></script>

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload"
  href="https://fonts.googleapis.com/css2?family=Lora:wght@400;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap"
  as="style" onload="this.onload=null;this.rel='stylesheet'">

{{- $assets := .Site.Data.assets }}
<link rel="stylesheet" href="{{ printf $assets.highlightjs.css.url $assets.highlightjs.version }}"
  {{ with $assets.highlightjs.css.sri }} integrity="{{ . }}" {{ end }} media="print"
  onload="this.media='all';this.onload=null" crossorigin>
<script defer src="{{ printf $assets.highlightjs.js.url $assets.highlightjs.version }}"
  {{ with $assets.highlightjs.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
<script defer src="{{ printf $assets.fontawesome.js.url $assets.fontawesome.version }}"
  {{ with $assets.fontawesome.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>

{{ define "partials/get-bundles" }}
{{ $currentPage := . }}
{{ $bundles := slice $currentPage }}
{{ if and (ne $currentPage.Kind "taxonomy") (or (ne $currentPage $currentPage.FirstSection) (eq $currentPage.Kind "term")) }}
{{ $currentBundles := partial "get-bundles" $currentPage.Parent }}
{{ $bundles = $bundles | append $currentBundles }}
{{ end }}
{{ return $bundles }}
{{ end }}

{{- $enableMath := false }}
{{- if .Site.Params.math.handler }}
{{- $bundles := partial "get-bundles" . }}
{{- $enableMath = true }}
{{- range $bundles.Reverse }}
{{- if and (ne .Params.math nil) (ne .Params.math "") }}
{{- $enableMath = .Params.math }}
{{- end }}
{{- end }}
{{- end }}

{{- if and (eq .Site.Params.math.handler "katex") $enableMath }}
<link rel="stylesheet" href="{{ printf $assets.katex.css.url $assets.katex.version }}"
  {{ with $assets.katex.css.sri }} integrity="{{ . }}" {{ end }} media="print"
  onload="this.media='all';this.onload=null" crossorigin>
<script defer src="{{ printf $assets.katex.js.url $assets.katex.version }}" {{ with $assets.katex.js.sri }}
  integrity="{{ . }}" {{ end }} crossorigin></script>
<script defer src="{{ printf $assets.katex.autoRender.url $assets.katex.version }}"
  {{ with $assets.katex.autoRender.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
<script>
  document.addEventListener("DOMContentLoaded", function () {
    renderMathInElement(document.body, {
      delimiters: [
        { left: "$$", right: "$$", display: true },
        { left: "$", right: "$", display: false },
        { left: "\\(", right: "\\)", display: false },
        { left: "\\[", right: "\\]", display: true }
      ],
      {{- range $key, $value := .Site.Params.math.katex }}
      {{- if and (ne $value nil) (ne $value "") }}
      {{- $key | safeJS -}}: {{- $value | safeJS }},
      {{- end }}
      {{- end }}
    });
  });
</script>
{{- end }}

{{- if and .Site.GoogleAnalytics hugo.IsProduction }}
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin>
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.GoogleAnalytics }}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  gtag('js', new Date());
  gtag('config', '{{ .Site.GoogleAnalytics }}');
</script>
{{- end }}

{{ partial "custom-head" . }}

{{- with .Site.Params.icon }}
<link rel="icon" type="image/png" sizes="32x32" href="{{ (partial "get-icon" (dict "icon" . "size" 32)).Permalink }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ (partial "get-icon" (dict "icon" . "size" 180)).Permalink }}">
{{- end }}

{{ define "partials/get-icon" }}
{{ $icon := resources.GetMatch .icon }}
{{ $iconResized := $icon.Fill (printf "%sx%s Center" (string .size) (string .size)) }}
{{ return $iconResized }}
{{ end }}

{{- partial "components/schema" . }}
{{- partial "components/opengraph" . }}
{{- range .AlternativeOutputFormats }}
{{- printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{- end }}